package com.yanqu.road.server.manger.activity.shushan;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.shushan.ShuShanBuildData;
import com.yanqu.road.entity.activity.shushan.ShuShanDiscipleData;
import com.yanqu.road.entity.activity.shushan.ShuShanLiLianGridData;
import com.yanqu.road.entity.activity.shushan.ShuShanUserData;
import com.yanqu.road.entity.activity.shushan.config.*;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.logic.bussiness.activity.ShuShanBusiness;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.pb.activity.ShuShanProto;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.shushanmodule.ShuShanModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.ForbiddenWordMgr;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description 蜀山
 * @Author cwq
 * @Data 2022/3/8 11:36
 */
public class ShuShanMgr extends TempMgr {

    private static ActivityInfo activityInfo;

    private static ShuShanActivityConfig config;

    private static Map<Long, ShuShanUserInfo> userInfoMap = new ConcurrentHashMap<>();

    /**
     * 在活动里的玩家集合
     */
    private static Set<Long> inActivitySet = new ConcurrentHashSet<>();

    /**
     * 上次刷新玩家修炼时间
     */
    public static volatile int lastRefreshTime = 0;

    private static Random random = new Random();

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }


    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean save() {
        for (ShuShanUserInfo userInfo : userInfoMap.values()) {
            userInfo.save();
        }
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }


    public static synchronized void reloadActivityData() {
        getLogger().info("reload shushan Activity start");
        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.ShuShanActivity.getValue());
        if (openActivityInfoList.isEmpty()) {
            getLogger().info("no shushan Activity in show time");
            activityInfo = null;
            config = null;
            userInfoMap.clear();
            inActivitySet.clear();
        } else {
            ActivityInfo tempActivityInfo = openActivityInfoList.get(0);

            List<Integer> activityIdList = new ArrayList<>();
            activityIdList.add(tempActivityInfo.getActivityId());

            Map<String, ActivityConfig> activityConfigMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(tempActivityInfo.getActivityId());
            ShuShanActivityConfig shuShanActivityConfig = new ShuShanActivityConfig();

            shuShanActivityConfig.setBuildConfigList(ShuShanBusiness.getShuiHuYeZiCardCardConfigList(tempActivityInfo.getActivityId()));
            shuShanActivityConfig.setSkillConfigList(ShuShanBusiness.getShuShanSkillConfigList(tempActivityInfo.getActivityId()));
            shuShanActivityConfig.setLiLianConfigList(ShuShanBusiness.getShuShanLiLianConfigList(tempActivityInfo.getActivityId()));
            shuShanActivityConfig.setEventConfigList(ShuShanBusiness.getShuShanEventConfigList(tempActivityInfo.getActivityId()));
            shuShanActivityConfig.setLiLianEncounterConfigList(ShuShanBusiness.getShuShanRewardConfigList(tempActivityInfo.getActivityId()));
            shuShanActivityConfig.parseConfig(activityConfigMap);

            config = shuShanActivityConfig;
            boolean initDB = true;
            if (activityInfo != null && activityInfo.getActivityId() == tempActivityInfo.getActivityId()) {
                initDB = false;
            }
            activityInfo = tempActivityInfo;
            if (initDB) {
                initDB();
            }
        }
        for (GamePlayer gamePlayer : GamePlayerMgr.getAllOnlinePlayer()) {
            ShuShanModule shuShanModule = gamePlayer.getModule(ShuShanModule.class);

            shuShanModule.sendConfigToClient();
            shuShanModule.initUserData();
            shuShanModule.synUserData();
        }
        getLogger().info("reload shushan Activity finish");
    }

    public static void initDB() {
        // 加载玩家
        userInfoMap.clear();
        List<ShuShanUserData> userList = ShuShanBusiness.getShuShanUserDataList(activityInfo.getActivityId());
        userList.forEach(e -> {
            userInfoMap.put(e.getUserId(), new ShuShanUserInfo(e));
        });
        Map<Long, Map<Integer, ShuShanBuildData>> buildMap = ShuShanBusiness.getShuShanBuildDataMap(activityInfo.getActivityId());
        for (Map.Entry<Long, Map<Integer, ShuShanBuildData>> entry : buildMap.entrySet()) {
            long userId = entry.getKey();
            ShuShanUserInfo userInfo = userInfoMap.get(userId);
            if (userInfo == null) {
                continue;
            }
            userInfo.setBuildDataMap(entry.getValue());
        }
        Map<Long, List<ShuShanDiscipleData>> discipleDataMap = ShuShanBusiness.getShuShanDiscipleDataMap(activityInfo.getActivityId());
        for (Map.Entry<Long, List<ShuShanDiscipleData>> entry : discipleDataMap.entrySet()) {
            long userId = entry.getKey();
            ShuShanUserInfo userInfo = userInfoMap.get(userId);
            if (userInfo == null) {
                continue;
            }
            Map<Integer, ShuShanDiscipleData> discipleMap = new ConcurrentHashMap<>();
            int maxId = 0;
            for (ShuShanDiscipleData item : entry.getValue()) {
                if (!item.getIsDelete()) {
                    discipleMap.put(item.getId(), item);
                }
                if (maxId == 0 || item.getId() > maxId) {
                    maxId = item.getId();
                }
            }
            userInfo.setDiscipleDataMap(discipleMap);
            userInfo.setMaxId(new AtomicInteger(maxId));
        }
        Map<Long, Map<Integer, ShuShanLiLianGridData>> liLianGridDataMap = ShuShanBusiness.getShuShanLiLianGridDataMap(activityInfo.getActivityId());
        for (Map.Entry<Long, Map<Integer, ShuShanLiLianGridData>> entry : liLianGridDataMap.entrySet()) {
            long userId = entry.getKey();
            ShuShanUserInfo userInfo = userInfoMap.get(userId);
            if (userInfo == null) {
                continue;
            }
            userInfo.setLiLianGridDataMap(entry.getValue());
        }

    }

    /**
     * 是否玩家可以进入活动
     */
    public static int canEntryActivity(GamePlayer player, int activityId) {
        if (activityInfo == null || activityInfo.getActivityId() != activityId) {
            return GameErrorCode.E_SHUSHAN_ACTIVITY_NO_OPEN;
        }
        if (!ActivityMgr.activityInShowTime(activityInfo)) {
            return GameErrorCode.E_SHUSHAN_ACTIVITY_NO_OPEN;
        }
        if (!SystemOpenMgr.systemOpen(player, eSystemId.ShuShan.getValue())) {
            return GameErrorCode.E_SHUSHAN_ACTIVITY_NO_UNLOCK;
        }
        // 展示期不进入
        if (!ActivityMgr.activityInTime(activityInfo)) {
            return GameErrorCode.E_SHUSHAN_NO_OPEN;
        }
        return 0;
    }

    /**
     * 刷新每个玩家的修炼情况
     */
    public static synchronized void refresh() {
        if (ShuShanMgr.getActivityInfo() == null) {
            return;
        }
        if (lastRefreshTime > ShuShanMgr.getActivityInfo().getEndTime()) {
            return;
        }
        int refreshTime = (int) (Math.min(DateHelper.getCurrentSecond(), ShuShanMgr.getActivityInfo().getEndTime()));
        for (ShuShanUserInfo userInfo : userInfoMap.values()) {
            synchronized (userInfo) {
                userInfo.refreshExercise(refreshTime);
                userInfo.refreshLiLianGrid(refreshTime);
            }
        }
        lastRefreshTime = DateHelper.getCurrentSecond();
    }


    /**
     * 检查队名合法性
     *
     * @param name
     * @return
     */
    public static short checkName(String name) {
        if (StringUtils.isNullOrEmpty(name)) {
            return GameErrorCode.E_SHUSHAN_NAME_NO_EMPTY;
        }
        int nameLength = StringUtils.getStringLen(name);
        if (nameLength > config.getSHUSHAN_NAME_LENGTH_LIMIT()) {
            return GameErrorCode.E_NAME_LENGTH_OVER;
        }
        //敏感字过滤
        if (ForbiddenWordMgr.isNickNameForbidden(name)) {
            return GameErrorCode.E_SHUSHAN_NAME_FORBIDDEN;
        }
        return 0;
    }

    /**
     * 同步玩家信息
     */
    public static void synUserData(GamePlayer player, boolean getLiLianInfoList) {
        if (player != null) {
            ShuShanUserInfo userInfo = getShuShanUserInfo(player, true);
            userInfo.refreshExercise(DateHelper.getCurrentSecond());
            player.sendPacket(ClientProtocol.U_SHUSHAN_GET_USER_DATA, userInfo.builderShuShanRespMsg(getLiLianInfoList));
        }
    }

    /**
     * 获取玩家信息
     *
     * @param player
     * @param newIfNull
     * @return
     */
    private static ShuShanUserInfo getShuShanUserInfo(GamePlayer player, boolean newIfNull) {
        ShuShanUserInfo userInfo = userInfoMap.get(player.getUserId());
        if (userInfo == null && newIfNull) {
            synchronized (userInfoMap) {
                // 初始化玩家信息
                userInfo = userInfoMap.get(player.getUserId());
                if (userInfo == null) {
                    int now = DateHelper.getCurrentSecond();
                    ShuShanUserData shuShanUserData = new ShuShanUserData();
                    shuShanUserData.setActivityId(activityInfo.getActivityId());
                    shuShanUserData.setUserId(player.getUserId());
                    UserInfo userBaseInfo = UserMgr.getUserInfo(shuShanUserData.getUserId());
                    String defaultName = MultipleLanguageMgr.randomShuShanName(player.getLanguage());
                    shuShanUserData.setPartyName(defaultName);
                    shuShanUserData.setGetTimes(ShuShanMgr.getConfig().getSHUSHAN_SHANMEN_SHUA_MAX());
                    shuShanUserData.setGetRefreshTime(now);
                    shuShanUserData.setBuyGetRefreshTime(now);
                    shuShanUserData.setExitTime(now);
                    shuShanUserData.setInsertOption();
                    userInfo = new ShuShanUserInfo(shuShanUserData);
                    // 初始化解锁 建筑信息
                    userInfo.initBuild(player);
                    userInfo.refreshChooseDisciple(userBaseInfo.getLanguage());
                    userInfo.randomDailyEventId(now);
                    userInfoMap.put(player.getUserId(), userInfo);
                }
            }
        }
        return userInfo;
    }


    /**
     * 离开系统
     *
     * @param player
     */
    public static void exitSystem(GamePlayer player) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, false);
        if (userInfo != null && inActivitySet.contains(player.getUserId())) {
            userInfo.exit();
            inActivitySet.remove(player.getUserId());
        }
    }

    /**
     * 进入活动
     *
     * @param player
     * @return
     */
    public static ShuShanProto.ShuShanEnterRespMsg.Builder enter(GamePlayer player) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            inActivitySet.add(player.getUserId());
            return userInfo.enter();
        }
    }


    /**
     * 取名
     *
     * @param name
     */
    public static ShuShanProto.ShuShanTakeNameRespMsg.Builder takeName(GamePlayer player, String name) {
        ShuShanProto.ShuShanTakeNameRespMsg.Builder builder = ShuShanProto.ShuShanTakeNameRespMsg.newBuilder();
        int ret = ShuShanMgr.checkName(name);
        if (ret != 0) {
            builder.setRet(ret);
            return builder;
        }
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            if (!userInfo.canTakeName()) {
                builder.setRet(GameErrorCode.E_SHUSHAN_ALREADY_HAS_A_NAME);
                return builder;
            }
            // 只允许改一次
            userInfo.takeName(name, false);
            builder.setUserInfo(userInfo.buildShuShanUserInfo());
        }
        builder.setRet(0);
        return builder;
    }


    /**
     * 弟子招收和刷新
     *
     * @param type
     * @param index
     */
    public static ShuShanProto.ShuShanGetDiscipleRespMsg.Builder getDisciple(GamePlayer player, int type, int index) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            return userInfo.getDisciple(player, type, index);
        }
    }

    /**
     * 购买选拔次数
     *
     * @param player
     * @param num
     * @return
     */
    public static ShuShanProto.ShuShanBuyGetTimesRespMsg.Builder buyGetTimes(GamePlayer player, int num) {
        ShuShanProto.ShuShanBuyGetTimesRespMsg.Builder builder = ShuShanProto.ShuShanBuyGetTimesRespMsg.newBuilder();
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            // 判断道具是否充足
            if(num <= 0){
                builder.setRet(GameErrorCode.E_BAG_USE_GOODS_COUNT_LESS_ONE);
                return builder;
            }
            GoodsInfo goodsInfo = GoodsMgr.getGoodsById(eItemId.SHU_SHAN_GOOD_EXERCISE.getValue());
            if(goodsInfo == null){
                builder.setRet(GameErrorCode.E_BAG_ITEM_NO_EXIST);
                return builder;
            }
            Property consume = new Property(eItemId.SHU_SHAN_GOOD_EXERCISE.getValue(), num);
            if (!player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.ShuShan, eLogMoneyType.ShuShanBuyGetTimesCost)) {
                builder.setRet(GameErrorCode.E_BAG_INGOTS_NO_ENOUGH);
                return builder;
            }
            int addNum = goodsInfo.getParamList().get(0).intValue() * num;
            userInfo.addGetTimes(addNum, true);
            builder.setUserInfo(userInfo.buildShuShanUserInfo());
        }
        builder.setRet(0);
        return builder;
    }


    /**
     * 修炼建筑
     *
     * @param player
     * @param type
     * @return
     */
    public static ShuShanProto.ShuShanUpBuildRespMsg.Builder upBuild(GamePlayer player, int type) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            return userInfo.upBuild(player, type);
        }
    }

    /**
     * 入世(踢出弟子)
     *
     * @param player
     * @param id
     * @return
     */
    public static ShuShanProto.ShuShanKickOutDiscipleRespMsg.Builder kickOut(GamePlayer player, int id) {
        ShuShanProto.ShuShanKickOutDiscipleRespMsg.Builder builder = ShuShanProto.ShuShanKickOutDiscipleRespMsg.newBuilder();
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            userInfo.kickOutDisciple(id);
            builder.addAllBuildInfoList(userInfo.buildShuShanBuildInfoList());
            builder.addAllOwnDiscipleList(userInfo.buildShuShanDiscipleInfoList());
            builder.addAllLiLianInfoGridList(userInfo.buildShuShanLiLianGridInfoList());
            builder.setRet(0);
            return builder;
        }
    }

    /**
     * 领取事件奖励
     *
     * @param player
     * @param type
     * @param optionsId
     * @return
     */
    public static ShuShanProto.ShuShanReceiveEventRewardRespMsg.Builder receiveEventReward(GamePlayer player, int type, int optionsId, int eventId) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            return userInfo.receiveEventReward(player, type, optionsId, eventId);
        }
    }

    /**
     * 领取引导奖励
     *
     * @param player
     */
    public static ShuShanProto.ShuShanReceiveGuideRewardRespMsg.Builder receiveGuideReward(GamePlayer player) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            return userInfo.receiveGuideReward(player);
        }
    }

    /**
     * 获取历练格子信息
     *
     * @param player
     * @param id
     * @return
     */
    public static ShuShanProto.ShuShanGetLiLianGridInfoRespMsg.Builder getLiLianGrad(GamePlayer player, int id) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            return userInfo.getLiLianGrad(id);
        }
    }

    /**
     * 快速修炼
     */
    public static ShuShanProto.ShuShanGoodExerciseRespMsg.Builder goodExercise(GamePlayer player, int num) {
        ShuShanProto.ShuShanGoodExerciseRespMsg.Builder builder = ShuShanProto.ShuShanGoodExerciseRespMsg.newBuilder();
        if(num <= 0){
            builder.setRet(GameErrorCode.E_BAG_USE_GOODS_COUNT_LESS_ONE);
            return builder;
        }
        Property consume = new Property(eItemId.SHU_SHAN_GOOD_EXERCISE.getValue(), num);
        if (!player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.ShuShan, eLogMoneyType.ShuShanGoodExerciseCost)) {
            builder.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return builder;
        }
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            // 判断是否有弟子再休息
            if (!userInfo.hasExerciseDisciple()) {
                builder.setRet(GameErrorCode.E_SHUSHAN_THE_NO_HAVE_EXERCISE_DISCIPLE);
                return builder;
            }
            int times = ShuShanMgr.getConfig().getSHUSHAN_STUDY_TOKEN_ADDNUM() * num;

            List<ShuShanProto.ShuShanGoodExerciseResult> resultList = userInfo.touchGoodExercise(times);
            builder.addAllGoodExerciseResultList(resultList);
            builder.setUserInfo(userInfo.buildShuShanUserInfo());
            builder.addAllBuildInfoList(userInfo.buildShuShanBuildInfoList());
            builder.addAllOwnDiscipleList(userInfo.buildShuShanDiscipleInfoList());
            builder.setRet(0);
            return builder;
        }
    }


    /**
     * 派遣历练 / 或者 领取坑位奖励
     *
     * @param id
     * @param type
     */
    public static ShuShanProto.ShuShanDispatchLiLianRespMsg.Builder dispatch(GamePlayer player, int id, int type, int discipleId) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, true);
        synchronized (userInfo) {
            return userInfo.dispatch(player, id, type, discipleId);
        }
    }


    public static ShuShanProto.SyncShuShanConfig.Builder builderSyncShuShanConfigRespMsg() {
        ShuShanProto.SyncShuShanConfig.Builder builder = ShuShanProto.SyncShuShanConfig.newBuilder();
        for (ShuShanBuildConfig item : config.getBuildConfigList()) {
            ShuShanProto.ShuShanBuildConfig.Builder builderConfig = ShuShanProto.ShuShanBuildConfig.newBuilder();
            builderConfig.setId(item.getId());
            builderConfig.setType(item.getType());
            builderConfig.setLevel(item.getLevel());
            builderConfig.setUpgradCost(item.getUpgradCost());
            builderConfig.setMaxStudent(item.getMaxStudent());
            builderConfig.setUnlock(item.getUnlock());
            builderConfig.setParam(item.getParam());
            builder.addBuildList(builderConfig);
        }
        for (ShuShanSkillConfig item : config.getSkillConfigList()) {
            ShuShanProto.ShuShanSkillConfig.Builder skillConfig = ShuShanProto.ShuShanSkillConfig.newBuilder();
            skillConfig.setId(item.getId());
            skillConfig.setType(item.getType());
            skillConfig.setLittleType(item.getLittleType());
            skillConfig.setLevel(item.getLevel());
            skillConfig.setAdd(item.getAdd());
            skillConfig.setStudyP(item.getStudyP());
            builder.addSkillList(skillConfig);
        }
        for (ShuShanLiLianConfig item : config.getLiLianConfigList()) {
            ShuShanProto.ShuShanLiLianConfig.Builder liLianConfig = ShuShanProto.ShuShanLiLianConfig.newBuilder();
            liLianConfig.setId(item.getId());
            liLianConfig.setType(item.getType());
            liLianConfig.setReward(item.getReward());
            liLianConfig.setUnlock(item.getUnlock());
            liLianConfig.setPic(item.getPic());
            liLianConfig.setPCode(item.getpCode());
            liLianConfig.setSpLimit(item.getSpLimit());
            liLianConfig.setNameCode(item.getNameCode());
            builder.addLiLianList(liLianConfig);
        }
        for (ShuShanEventConfig item : config.getEventConfigList()) {
            ShuShanProto.ShuShanEventConfig.Builder eventConfig = ShuShanProto.ShuShanEventConfig.newBuilder();
            eventConfig.setId(item.getId());
            eventConfig.setType(item.getType());
            eventConfig.setIcon(item.getIcon());
            eventConfig.setReward(item.getReward());
            eventConfig.setUnlock(item.getUnlock());
            builder.addEventList(eventConfig);
        }
        for (ShuShanRewardConfig item : config.getLiLianEncounterConfigList()) {
            ShuShanProto.ShuShanRewardConfig.Builder rewardConfig = ShuShanProto.ShuShanRewardConfig.newBuilder();
            rewardConfig.setId(item.getId());
            rewardConfig.setLevel(item.getLevel());
            rewardConfig.setPowerType(item.getPowerType());
            rewardConfig.setPower(item.getPower());
            rewardConfig.setCosttime(item.getCosttime());
            rewardConfig.setReward(item.getReward());
            builder.addRewardList(rewardConfig);
        }
        return builder;
    }

    /**
     * 是否是蜀山 声望道具
     *
     * @return
     */
    public static boolean isPrestige(int goodsId) {
        return eItemId.SHU_SHAN_PRESTIGE.getValue() == goodsId;
    }

    /**
     * 加声望
     *
     * @param player
     * @param num
     */
    public static void addPrestige(GamePlayer player, long num) {
        if (!ActivityMgr.activityInShowTime(activityInfo)) {
            return;
        }
        if (!SystemOpenMgr.systemOpen(player, eSystemId.ShuShan.getValue())) {
            return;
        }
        ShuShanUserInfo userInfo = getShuShanUserInfo(player, false);
        if (userInfo == null) {
            return;
        }
        synchronized (userInfo) {
            userInfo.addPrestige(num);
        }
    }

    public static ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public static ShuShanActivityConfig getConfig() {
        return config;
    }

    public static Set<Long> getInActivitySet() {
        return inActivitySet;
    }

    public static Random getRandom() {
        return random;
    }

    /**
    * 描述：管理员变更名称
    * 作者：zrq
    * 时间：2022/8/5
    * 参数：
    玩家对象，名称
    * 返回值：操作码
    **/
    public static int adminChangeName(GamePlayer player, String name) {
        ShuShanUserInfo userInfo = ShuShanMgr.getShuShanUserInfo(player, false);
        if(null == userInfo){
            return GameErrorCode.E_SYSTEM_NO_OPEN;
        }
        synchronized (userInfo) {
            userInfo.takeName(name, true);
        }
        return 0;
    }

    public static String adminQueryName(long userId) {
        ShuShanUserInfo userInfo = userInfoMap.get(userId);
        if (null == userInfo) {
            return "";
        }
        return userInfo.getPartyName();
    }
}

